 package handling.world.messenger;

 import client.MapleCharacter;
 import handling.channel.ChannelServer;
 import handling.world.WorldFindService;
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Collection;







 public class MapleMessenger
   implements Serializable
 {
   private static final long serialVersionUID = 9179541993413738569L;
   private final MapleMessengerCharacter[] members;
   private final String[] silentLink;
   private final MessengerType type;
   private final boolean hide;
   private int id;

   public MapleMessenger(int id, MapleMessengerCharacter chrfor, MessengerType type, boolean gm) {
/*  27 */     this.id = id;
/*  28 */     this.type = type;
/*  29 */     this.hide = gm;
/*  30 */     this.members = new MapleMessengerCharacter[type.maxMembers];
/*  31 */     this.silentLink = new String[type.maxMembers];
/*  32 */     this.members[0] = chrfor;
   }

   public MessengerType getType() {
/*  36 */     return this.type;
   }

   public boolean isHide() {
/*  40 */     return this.hide;
   }

   public void addMembers(int pos, MapleMessengerCharacter chrfor) {
/*  44 */     if (this.members[pos] != null) {
       return;
     }
/*  47 */     this.members[pos] = chrfor;
   }

   public boolean containsMembers(MapleMessengerCharacter member) {
/*  51 */     return (getPositionByName(member.getName()) != -1);
   }

   public void addMember(MapleMessengerCharacter member) {
/*  55 */     int position = getLowestPosition();
/*  56 */     if (position != -1) {
/*  57 */       addMembers(position, member);
     }
   }

   public void removeMember(MapleMessengerCharacter member) {
/*  62 */     int position = getPositionByName(member.getName());
/*  63 */     if (position != -1) {
/*  64 */       this.members[position] = null;
     }
   }

   public void silentRemoveMember(MapleMessengerCharacter member) {
/*  69 */     int position = getPositionByName(member.getName());
/*  70 */     if (position != -1) {
/*  71 */       this.members[position] = null;
/*  72 */       this.silentLink[position] = member.getName();
     }
   }

   public void silentAddMember(MapleMessengerCharacter member) {
/*  77 */     for (int i = 0; i < this.silentLink.length; i++) {
/*  78 */       if (this.silentLink[i] != null && this.silentLink[i].equalsIgnoreCase(member.getName())) {
/*  79 */         addMembers(i, member);
/*  80 */         this.silentLink[i] = null;
         return;
       }
     }
   }




   public void updateMember(MapleMessengerCharacter member) {
/*  90 */     for (int i = 0; i < this.members.length; i++) {
/*  91 */       MapleMessengerCharacter chr = this.members[i];
/*  92 */       if (chr != null && chr.equals(member)) {
/*  93 */         this.members[i] = null;
/*  94 */         addMembers(i, member);
         return;
       }
     }
   }




   public int getMemberSize() {
/* 104 */     int ret = 0;
/* 105 */     for (MapleMessengerCharacter member : this.members) {
/* 106 */       if (member != null) {
/* 107 */         ret++;
       }
     }
/* 110 */     return ret;
   }




   public int getLowestPosition() {
/* 117 */     for (int i = 0; i < this.members.length; i++) {
/* 118 */       if (this.members[i] == null) {
/* 119 */         return i;
       }
     }
/* 122 */     return -1;
   }





   public int getPositionByName(String name) {
/* 130 */     for (int i = 0; i < this.members.length; i++) {
/* 131 */       MapleMessengerCharacter messengerchar = this.members[i];
/* 132 */       if (messengerchar != null && messengerchar.getName().equalsIgnoreCase(name)) {
/* 133 */         return i;
       }
     }
/* 136 */     return -1;
   }

   public MapleMessengerCharacter getMemberByPos(int pos) {
/* 140 */     return this.members[pos];
   }




   public int getId() {
/* 147 */     return this.id;
   }

   public void setId(int id) {
/* 151 */     this.id = id;
   }


   public int hashCode() {
/* 156 */     return 31 + this.id;
   }


   public boolean equals(Object obj) {
/* 161 */     if (this == obj) {
/* 162 */       return true;
     }
/* 164 */     if (obj == null) {
/* 165 */       return false;
     }
/* 167 */     if (getClass() != obj.getClass()) {
/* 168 */       return false;
     }
/* 170 */     MapleMessenger other = (MapleMessenger)obj;
/* 171 */     return (this.id == other.id);
   }

   public Collection<MapleMessengerCharacter> getMembers() {
/* 175 */     return Arrays.asList(this.members);
   }




   public boolean isMonitored() {
/* 182 */     int ch = -1;
/* 183 */     for (MapleMessengerCharacter member : this.members) {
/* 184 */       if (member != null) {
/* 185 */         ch = WorldFindService.getInstance().findChannel(member.getName());
/* 186 */         if (ch != -1) {
/* 187 */           MapleCharacter player = ChannelServer.getInstance(ch).getPlayerStorage().getCharacterByName(member.getName());
/* 188 */           if (player != null && player.getClient() != null && player.getClient().isMonitored()) {
/* 189 */             return true;
           }
         }
       }
     }
/* 194 */     return false;
   }

   public String getMemberNamesDEBUG() {
/* 198 */     StringBuilder sb = new StringBuilder();
/* 199 */     for (int i = 0; i < this.members.length; i++) {
/* 200 */       if (this.members[i] != null) {
/* 201 */         sb.append(this.members[i].getName());
/* 202 */         if (i != this.members.length - 1) {
/* 203 */           sb.append(',');
         }
       }
     }
/* 207 */     return sb.toString();
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\world\messenger\MapleMessenger.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */